package com.pay.plat.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pay.entity.ZfbInLog;
import com.pay.entity.ZfbMember;
import com.pay.plat.annotation.AuthResource;
import com.pay.plat.mapping.MappingUtils;
import com.pay.service.IZfbInLogService;
import com.pay.service.IZfbMemberService;
import com.pay.utils.BasePage;
import com.pay.utils.FunctionUtils;
import com.pay.utils.ResponseData;

@Controller
public class RobtoController {

	@Autowired
	private IZfbMemberService zfbMemberService ;
	
	@Autowired
	private IZfbInLogService zfbInLogService ;
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showZfbRobtoManager)
	public ModelAndView showZfbRobtoManager(ZfbMember zfbMember,BasePage<ZfbMember> page,Integer loginId) {
		zfbMemberService.getList(zfbMember,page) ;
		ModelAndView m = new ModelAndView(MappingUtils.showZfbRobtoManager);
		m.addObject("zfbMember", zfbMember) ;
		m.addObject("list", page) ;
		m.addObject("loginId", loginId) ;
		return m ;
	}
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showZfbRobtoAdd)
	public ModelAndView showZfbRobtoAdd(Integer loginId) {
		ModelAndView m = new ModelAndView(MappingUtils.showZfbRobtoAdd);
		m.addObject("loginId", loginId) ;
		return m ;
	}
	
	@ResponseBody
	@AuthResource(url=MappingUtils.showZfbRobtoAdd)
	@RequestMapping(value=MappingUtils.doZfbRobtoAdd)
	public ResponseData doZfbRobtoAdd(ZfbMember zfbMember) {
		return zfbMemberService.doZfbRobtoAdd(zfbMember) ;
	}
	
	@AuthResource
	@RequestMapping(value=MappingUtils.showZfbRobtoEdit)
	public ModelAndView showZfbRobtoEdit(Integer id,Integer loginId) {
		ZfbMember zfbMember = zfbMemberService.getById(id);
		ModelAndView m = new ModelAndView(MappingUtils.showZfbRobtoEdit);
		m.addObject("zfbMember", zfbMember) ;
		m.addObject("loginId", loginId) ;
		return m ;
	}
	
	@AuthResource(url=MappingUtils.showZfbRobtoEdit)
	@ResponseBody
	@RequestMapping(value=MappingUtils.doZfbRobtoEdit)
	public ResponseData doZfbRobtoEdit(ZfbMember zfbMember) {
		return zfbMemberService.doZfbRobtoEdit(zfbMember) ;
	}
	
	@ResponseBody
	@AuthResource
	@RequestMapping(value=MappingUtils.doZfbRobtoDelete)
	public ResponseData doZfbRobtoDelete(String ids,Integer loginId) {
		boolean result = zfbMemberService.removeByIds(FunctionUtils.getList(ids.split(",")));
		return result ? ResponseData.ok() : ResponseData.baseError("删除未成功") ;
	}
	
	@AuthResource
	@ResponseBody
	@RequestMapping(value=MappingUtils.doZfbSwitch)
	public ResponseData doZfbSwitch(Integer id,Integer status) {
		return zfbMemberService.doZfbSwitch(id,status) ;
	}
	
	
	@AuthResource
	@ResponseBody
	@RequestMapping(value=MappingUtils.showZfbRobtoIncome)
	public ModelAndView showZfbRobtoIncome(ZfbInLog zfbInLog,BasePage<ZfbInLog> basePage,Integer loginId) {
		zfbInLogService.getList(zfbInLog,basePage) ;
		List<ZfbMember> zfbMemberList = zfbMemberService.list(null);
		ModelAndView m = new ModelAndView(MappingUtils.showZfbRobtoIncome);
		m.addObject("loginId", loginId) ;
		m.addObject("list", basePage) ;
		m.addObject("zfbInLog", zfbInLog) ;
		m.addObject("zfbMemberList", zfbMemberList) ;
		return m ; 
	}
}
